package cn.zjitc.quickstart.user.dao;

import cn.zjitc.quickstart.user.domain.User;
import cn.zjitc.quickstart.user.util.DruidUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class UserDao {
    private JdbcTemplate template = new JdbcTemplate(DruidUtils.getDataSource());
    public User findUserByUsernameAndPassword(String username, String password) {
        //1.编写sql
        String sql = "select * from user where username = ? and password = ?";
        //2.调用query方法
        try {
           return template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), username, password);
        } catch (DataAccessException e) {
            return  null;
        }
    }
}
